<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <button id="btnGet">get</button>
    <button id="btnPost">post</button>
    <button id="btnJsonp">btnJsonp</button>
    <script>
    $(function(){
        
            // 测试jsonp请求
            $("#btnJsonp").on('click', function () {
                $.ajax({
                    method: 'GET',
                    url: 'http://127.0.0.1/api/jsonp',
                    dataType: 'jsonp',
                    success: function (res) {
                        console.log(res);
                    }
                })
            })

            // 测试
            $("#btnGet").on('click', function () {
                $.ajax({
                    method: 'get',
                    url: 'http://127.0.0.1/api/get',
                    data: { name: 'zs', age: 20 },
                    success: (res) => {
                        console.log(res);
                    }
                })

            })



            $("#btnPost").on('click', function () {
                $.ajax({
                    method: 'POST',
                    url: 'http://127.0.0.1/api/post',
                    data: { bookname: '水浒传', auhtor: '施耐庵' },
                    success: (res) => {
                        console.log(res);
                    }
                })
            })


    })




    </script>
</body>

</html>